//
//  AppDelegate.m
//  CenturyInterconnection
//
//  Created by Tian Wei You on 16/4/5.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "AppDelegate.h"
#import "YLWTabBarController.h"
#import "LeftMenuViewController.h"
#import "RightMenuViewController.h"
#import "HomePageViewController.h"
#import "XXNavigationController.h"
#import <PgySDK/PgyManager.h>

#import <AdSupport/AdSupport.h>
#import "JPUSHService.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import "NewLeftMenuViewController.h"


@interface AppDelegate ()

@end

@implementation AppDelegate



//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"MONEYINDEX"];

<<<<<<< HEAD
//    应用统计
    UMConfigInstance.appKey = @"57e48a5967e58e32f9001892";
    UMConfigInstance.channelId = @"ShoesJoy";
    [MobClick startWithConfigure:UMConfigInstance];//配置以上参数后调用此方法初始化SDK！
    
=======
>>>>>>> parent of 58ffaa4... init
//    facebook登录
    [[FBSDKApplicationDelegate sharedInstance] application:application
     
                             didFinishLaunchingWithOptions:launchOptions];
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    [FBSDKSettings setAppID:@"1355592837802215"];
    
//    
    [FBSDKAppEvents logEvent:@"ActivatedApp"];
    
    
//    推送
    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    //Required
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];
    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
        
    }
    
    
    //Required
    // 如需继续使用pushConfig.plist文件声明appKey等配置内容，请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
//    [JPUSHService setupWithOption:launchOptions appKey:@"c426a653b637c5c508a1add9"
//                         channel:@"Publish channel"
//                apsForProduction:NO
//           advertisingIdentifier:advertisingId];
    

    [JPUSHService setupWithOption:launchOptions appKey:@"c426a653b637c5c508a1add9"
                          channel:@"Publish channel"
                 apsForProduction:YES
            ];
 
    
    
    
    //  关闭用户手势反馈，默认为开启。
//    [[PgyManager sharedPgyManager] setEnableFeedback:NO];
    
    
    
    //  设置用户反馈激活模式为三指拖动，默认为摇一摇。
    //  [[PgyManager sharedPgyManager] setFeedbackActiveType:kPGYFeedbackActiveTypeThreeFingersPan];
    
    //  设置用户反馈界面的颜色，会影响到Title的背景颜色和录音按钮的边框颜色，默认为0x37C5A1(绿色)。
    //  [[PgyManager sharedPgyManager] setThemeColor:[UIColor blackColor]];
    
    //  设置摇一摇灵敏度，数字越小，灵敏度越高，默认为2.3。
    //  [[PgyManager sharedPgyManager] setShakingThreshold:3.0];
    
    //  是否显示蒲公英SDK的Debug Log，如果遇到SDK无法正常工作的情况可以开启此标志以确认原因，默认为关闭。
//    [[PgyManager sharedPgyManager] setEnableDebugLog:YES];
    
    //启动基本SDK
//    [[PgyManager sharedPgyManager] startManagerWithAppId:@"9df0d63dc862cb5c1d51f1d0704f9e2d"];
    
    //启动更新检查SDK
    //[[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"9df0d63dc862cb5c1d51f1d0704f9e2d"];
    
    
    
    
    //YLWTabBarController *vc=[[YLWTabBarController alloc]init];
    HomePageViewController *vc=[[HomePageViewController alloc] init];
    //XXNavigationController *vcc=[[XXNavigationController alloc] initWithRootViewController:vc];
    //UINavigationController * vcc = [[UINavigationController alloc] initWithRootViewController:vc];
    
    SlideNavigationController * vcc = [[SlideNavigationController alloc] initWithRootViewController:vc];
    
    //影响按钮
    [[SlideNavigationController sharedInstance].navigationBar setTintColor:[UIColor whiteColor]];
    
    [[SlideNavigationController sharedInstance].navigationBar setBackgroundColor:[UIColor clearColor]];
    
    //导航栏
    [[SlideNavigationController sharedInstance].navigationBar setBarTintColor:[UIColor grayColor]];
    
    
    

    //SlideNavigationController
    LeftMenuViewController * leftMenu = [[LeftMenuViewController alloc] init];
    RightMenuViewController * rightMenu = [[RightMenuViewController alloc] init];
    
    [SlideNavigationController sharedInstance].leftMenu = leftMenu;
    [SlideNavigationController sharedInstance].rightMenu = rightMenu;
    [SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;
    
    
    UIButton *leftbutton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftbutton setImage:[UIImage imageNamed:@"nav_menu"] forState:UIControlStateNormal];
    [leftbutton addTarget:self action:@selector(goToNewLeftVC) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftbutton];
    [SlideNavigationController sharedInstance].leftBarButtonItem = leftBarButtonItem;
    
    // Creating a custom bar button for right menu
    UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [button setImage:[UIImage imageNamed:@"nav_me"] forState:UIControlStateNormal];
    [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;
    
//    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) {
//        NSString *menu = note.userInfo[@"menu"];
//        NSLog(@"Closed %@", menu);
//        
//    }];
    
//    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) {
//        NSString *menu = note.userInfo[@"menu"];
//        NSLog(@"Opened %@", menu);
//    }];
//    
//    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) {
//        NSString *menu = note.userInfo[@"menu"];
//        NSLog(@"Revealed %@", menu);
//    }];
    
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    self.window.rootViewController= vcc;
    return YES;
}
///*!
// * @abstract 设置角标(到服务器)
// *
// * @param value 新的值. 会覆盖服务器上保存的值(这个用户)
// *
// * @discussion 本接口不会改变应用本地的角标值.
// * 本地仍须调用 UIApplication:setApplicationIconBadgeNumber 函数来设置脚标.
// *
// * 本接口用于配合 JPush 提供的服务器端角标功能.
// * 该功能解决的问题是, 服务器端推送 APNs 时, 并不知道客户端原来已经存在的角标是多少, 指定一个固定的数字不太合理.
// *
// * JPush 服务器端脚标功能提供:
// *
// * - 通过本 API 把当前客户端(当前这个用户的) 的实际 badge 设置到服务器端保存起来;
// * - 调用服务器端 API 发 APNs 时(通常这个调用是批量针对大量用户),
// *   使用 "+1" 的语义, 来表达需要基于目标用户实际的 badge 值(保存的) +1 来下发通知时带上新的 badge 值;
// */
//+ (BOOL)setBadge:(NSInteger)value {
//    return YES;
//}

-(void)goToNewLeftVC
{
    NewLeftMenuViewController * newVC = [[NewLeftMenuViewController alloc]init];
    [[SlideNavigationController sharedInstance] pushViewController:newVC animated:YES];
}

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    /// Required - 注册 DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    // Required,For systems with less than or equal to iOS6
    [JPUSHService handleRemoteNotification:userInfo];
}

//点击查看消息，会调用；userInfo里面可以存放对应的信息（这个信息是管理后台手动添加的）
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    //如果处于后台(UIApplicationStateBackground)，这时候推送过来了消息，需要弹出alert提示
    
    if (    [UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
        
    }
    
    // IOS 7 Support Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}



- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    return [[FBSDKApplicationDelegate sharedInstance] application:application
            
                                                          openURL:url
            
                                                sourceApplication:sourceApplication
            
                                                       annotation:annotation
            
            ];
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
    [HJNSObjectRelease sendReleaseNotice];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     [FBSDKAppEvents activateApp];
    [HJNSObjectRelease createReleaseObserver];

}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
